<!-- 新增编辑查看 -->
<template>
  <el-dialog :visible.sync="params.show" @open="init" :before-close="cancel" class="dialog-form" width="370px">
    <DialogFormTitle slot="title" :title="params.title" />
    <el-form :model="formData" ref="formData" :inline="true" label-width="100px" label-position="left" :disabled="params.title === '详情'">
      <el-form-item label="名称" prop="name" :rules="[{ required: true, message: '不能为空' }]">
        <Input v-model.trim="formData.name" />
      </el-form-item>
      <el-form-item label="时间" prop="time" :rules="[{ required: true, message: '不能为空' }]">
        <DatePicker v-model="formData.time" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" />
      </el-form-item>
      <el-form-item label="状态" prop="state">
        <Select v-model="formData.state" :options="DISABLE" />
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <Textarea v-model.trim="formData.remark" />
      </el-form-item>
    </el-form>
    <span slot="footer">
      <el-button type="info" @click="cancel">关 闭</el-button>
      <el-button type="primary" @click="submit" v-if="params.title !== '详情'">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import mixin from '@/mixin/dialog-form'
// import { methodPost } from '@/api'
import { DISABLE } from '@/constants/basic-data'

export default {
  mixins: [mixin],
  props: {
    params: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      DISABLE
    }
  },
  methods: {
    /**
     * 提交
     */
    submit() {
      this.$refs.formData.validate(valid => {
        if (valid) {
          let url = null
          if (this.params.title === '新增') {
            url = '/xxx/add'
          } else {
            url = '/xxx/update'
          }
          /* methodPost(url, this.formData).then(res => {
            if (res.code === 200) {
              this.$message.success('操作成功')
              this.$emit('callback') // 更新列表数据
              this.cancel()
            } else {
              this.$message.error(res.remark)
            }
          }) */
        }
      })
    }
  }
}
</script>
